import {wxLogin,login} from "@/api/api.js"
var log = require('./log.js');
export async function request(url,data,method='post'){
	let header={};
	const Authorization = uni.getStorageSync('Authorization');
	if(Authorization){
		header.Authorization=Authorization;
	}
	let http = 'https://hms.keaizhu.com/miniapp';
	let http2 = 'http://192.168.31.18:8089/miniapp';
	return new Promise((resolve,reject)=>{
		uni.request({
			url:http+url,
			method,
			header,
			data,
			success(data) {
				log.info(url+JSON.stringify(data));
				if(data.header.Authorization){
					uni.setStorageSync('Authorization', data.header.Authorization);
				}
				if(data.statusCode==200){
					if(data.data.code==200){
						resolve(data.data);
					}else{
						uni.showToast({
						    title: data.data.message,
						    duration: 1500,
							icon:"none"
						});
						resolve(data.data);
						if(data.data.code==880){
							uni.removeStorageSync('Authorization');
							uni.switchTab({
								url:"/pages/tabbar/mine/mine"
							})
						}
					}	
				}else{
					console.log(data);
					uni.showToast({
						title:"网络错误",
						icon:"none",
						duration: 1500,
					})
					reject(data.data);
				}
			},
			fail(err){
				log.error(JSON.stringify(err));
				uni.showToast({
					title:"未知错误",
					icon:"none",
					duration: 1500,
				})
				reject(err);
			}
		})
	})
}